package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.entity.Device;
import com.zzyl.vo.DeviceDataGraphVo;
import com.zzyl.vo.DeviceVo;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface DeviceMapper {
    /**
     * 查询数据库中是否纯在同名设备
     *
     * @param deviceName
     * @return
     */
    @Select("select count(*) from device where device_name = #{deviceName}")
    int queryDeviceByDeviceName(String deviceName);

    /**
     * 插入设备信息
     *
     * @param device
     */
    void insertDevice(Device device);

    /**
     * 分页查询设备列表
     *
     * @param devicePageQueryDto
     * @return
     */
    Page<DeviceVo> queryPageQueryDevice(DevicePageQueryDto devicePageQueryDto);

    /**
     * 查询设备详细数据
     *
     * @param iotId
     * @return
     */
    DeviceVo queryDeviceDetailByIotId(String iotId);

    /**
     * 修改数据库设备备注名称
     *
     * @param device
     */
    void updateDevice(Device device);

    /**
     * 删除数据库设备
     *
     * @param iotId
     */
    @Delete("delete from device where iot_id = #{iotId}")
    void deleteDeviceByIotId(String iotId);

    /**
     * 按天统计查询指标数据
     *
     * @param iotId
     * @param startDateTime
     * @param functionId
     * @param endDateTime
     * @return
     */
    List<DeviceDataGraphVo> queryDeviceDataListByDay(@Param(value = "iotId") String iotId, @Param(value = "startDateTime") LocalDateTime startDateTime, @Param(value = "functionId") String functionId, @Param(value = "endDateTime") LocalDateTime endDateTime);

    /**
     * 按周统计查询指标数据
     *
     * @param iotId
     * @param startDateTime
     * @param functionId
     * @param endDateTime
     * @return
     */
    List<DeviceDataGraphVo> queryDeviceDataListByWeek(@Param(value = "iotId") String iotId, @Param(value = "startDateTime") LocalDateTime startDateTime, @Param(value = "functionId") String functionId, @Param(value = "endDateTime") LocalDateTime endDateTime);

    /**
     * 根据iotId通过床位查询老人护理人员Ids
     *
     * @param iotId
     * @return
     */
    List<Long> selectNursingIdsByIotIdWithBed(String iotId);

    /**
     * 通过老人查询护理员ids
     *
     * @param iotId
     * @return
     */
    List<Long> selectNursingIdsByIotIdWithElder(String iotId);


}
